<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2018/3/21
 * Time: 16:09
 */
namespace app\admin\controller;
use app\common\controller\Curt;
use  app\admin\model\Column as Columnmodel;
use think\Db;
use think\Session;

class  Article extends Curt {
    function __construct()
    {
        parent::__construct($upload = true,$uploadConfig = array(
            'input_name' => 'coverFile',//文本框name
            'data_field' => 'cover'//数据库字段
        ));
    }
    public function getall()
    {
//        Db::table('think_user')
//            ->where('name',['like','thinkphp%'],['like','%thinkphp'])
//            ->where('id',['>',0],['<>',10],'or')
//            ->find();
//        Db::table('think_user')
//            ->where('name',['like','thinkphp%'],['like','%thinkphp'])
//            ->where('id',5,['<>',10],'or')
//            ->find();
//        Db::table('think_user')->select(function($query){
//            $query->where('name','thinkphp')
//                ->whereOr('id','>',10);
//        });
//        Db::table('think_user')
//            ->where('name',['like','thinkphp%'],['like','%thinkphp'])
//            ->whereOr(function($query){
//                $query->where('id',['<',10],['>',100],'or');
//            })
//            ->select();
        $keyword=input('get.keyword');
        if($keyword){
            $where['title|b.name']=['like','%'.$keyword.'%'];
        }
        $alias=['ec_article'=>'a','ec_column'=>'b'];//传入数组批量设置数据表以及别名
        $join = [
                 ['ec_column','a.column_id=b.id', ],
             ];
        $list = $this->model ->alias($alias) ->join($join) ->order('id desc') ->where($where) ->field("a.*,b.name") ->paginate();
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
    }
    public function adddatabefter($res){
        $res['author']=Session::get('name');
        return $res;
    }
    /**
     * @param $id
     * 文章审核
     */
    public function reviewed($id)
    {
        if(input('reviewed')==1){
            $reviewed=2;
            $msg="已驳回";
        }else{
            $reviewed=1;
            $msg="已审核";
        }
        $arr = explode(',', $id);
        $i = 0;
        foreach ($arr as $k => $v) {
            if (!$v) {
                continue;
            }
            $this->model->isUpdate(true)->save(['id'=>$v,'review'=>$reviewed]);
            $i++;
        }
        $this->success($msg . $i . '条数据', $this->urlConfig['del_success']);
    }
}

